//
//  LCDeleteFile.m
//  LCMusicPlayer
//
//  Created by jiukuyinyue on 2017/9/30.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCDeleteFile.h"

@implementation LCDeleteFile


+(void)deleteFileWithISHasSuffix:(BOOL)iSHasSuffix {
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    NSString *document=[NSSearchPathForDirectoriesInDomains(13, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *folder = document;//[document stringByAppendingPathComponent:@"folder"];
    NSArray *fileList ;
    fileList =[fileManager contentsOfDirectoryAtPath:folder error:NULL];
    
    for (NSString *file in fileList) {
                NSLog(@"file=%@",file);
        if(iSHasSuffix){
            if ([file hasSuffix:@".mp3"] || [file hasSuffix:@".m4a"]) {
                NSString *path =[folder stringByAppendingPathComponent:file];
                //        NSLog(@"得到的路径=%@",path);
                
                BOOL blDele= [fileManager removeItemAtPath:path error:nil];
                if (blDele) {
                    //            NSLog(@"dele success");
                }else {
                    //            NSLog(@"dele fail");
                }
            }
        }else{
            NSString *path =[folder stringByAppendingPathComponent:file];
            //        NSLog(@"得到的路径=%@",path);
            
            BOOL blDele= [fileManager removeItemAtPath:path error:nil];
            if (blDele) {
                //            NSLog(@"dele success");
            }else {
                //            NSLog(@"dele fail");
            }
            
        }
        
    }
    
}

@end
